#!/bin/bash

# Here we figure out DL_SERVER, SOURCE_ROOT, WEB_DIR, etc.
. functions.sh

echo_and_log "--> Starting Vagrant post_provision_6.sh..."

echo_and_log "--> Add mysql-connector-java-5.1.38.jar file"

rsync -av -e "ssh -p 333 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i ${ID_RSA_PATH}" smx@${DL_SERVER}:/opt/www/ops30.sumilux.com/jar/ /usr/java/jdk1.8.0_45/jre/lib/ext/

 
echo_and_log "---> Modify cwebpdf environment variable..."

if [ -f /usr/local/tomcat/bin/catalina.sh ];then
  sed -i '/JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener/a\JAVA_OPTS="$JAVA_OPTS -Dwebpdf_home=/usr/local/webpdf"' /usr/local/tomcat/bin/catalina.sh
fi

echo_and_log "---> rysnc some xml files..."
if [ ! -d /usr/local/tomcat/conf/Catalina/localhost/ ]; then
  sudo mkdir -p /usr/local/tomcat/conf/Catalina/localhost/
fi

sudo cp $SOURCE_ROOT/vagrant/reader.xml /usr/local/tomcat/conf/Catalina/localhost/reader.xml
sudo cp $SOURCE_ROOT/vagrant/foxit-cwebpdf-filesystem.xml /usr/local/tomcat/conf/Catalina/localhost/foxit-cwebpdf-filesystem.xml
sudo cp $SOURCE_ROOT/vagrant/foxit-cwebpdf-collectiondata.xml /usr/local/tomcat/conf/Catalina/localhost/foxit-cwebpdf-collectiondata.xml

echo_and_log "----> Starting fxtomcat server"

sudo /etc/init.d/fxtomcat start
